home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -in_the_mag- / reader_requests / wild / support / wabl / showwabl / showwabl.c < prev    next >
C/C++ Source or Header  |  2000-02-23  |  3KB  |  111 lines

  1. /*
  2. **    ShowWABL: shows a WABL file. Useless, just to code a demo and check load routine...
  3. */
  4.  
  5. #include <wabl/wabl.h>
  6. #include <exec/exec.h>
  7. #include <exec/libraries.h>
  8. #include <dos/dos.h>
  9. #include <utility/tagitem.h>
  10. #include <utility/hooks.h>
  11. #include <inline/dos.h>
  12.  
  13. extern struct ExecBase *SysBase;
  14. extern struct Library *DOSBase;
  15.  
  16. #define    ARG_WABLINPUT    0
  17.  
  18. UBYTE    indent=0L;
  19. ULONG     *outfh;
  20. char    Separator[20]={27,'[','3','1','m',27,'[','4','0','m',9,9,0};
  21. char    Blue[11]={27,'[','3','3','m',27,'[','4','0','m',0};
  22. char    BlueD[11]={27,'[','3','3','m',27,'[','4','1','m',0};
  23. char    White[11]={27,'[','3','2','m',27,'[','4','0','m',0};
  24.  
  25. void ShowTree(struct WABLObject *obj)
  26. {
  27.  struct WABLObject *nob;
  28.  indent++;
  29.  while (nob=obj->WABL_O_Node.mln_Succ)
  30.   {
  31.    int i;
  32.    for (i=0;i<indent;i++)
  33.     {
  34.      FPutC(outfh,32);
  35.     } 
  36.    FPuts(outfh,&White);
  37.    FPuts(outfh,obj->WABL_O_Type);
  38.    FPuts(outfh,&Separator);
  39.    FPuts(outfh,obj->WABL_O_Name);
  40.    FPutC(outfh,10);
  41.    {
  42.     struct WABLAttr *att,*nat;
  43.     att=obj->WABL_O_Attrs.mlh_Head;
  44.     while (nat=att->WABL_A_Node.mln_Succ)
  45.      {
  46.       for (i=0;i<indent;i++)
  47.        {
  48.         FPutC(outfh,32);
  49.        } 
  50.       FPutC(outfh,'+');
  51.       FPuts(outfh,&Blue);
  52.       FPuts(outfh,att->WABL_A_Comm);
  53.       FPuts(outfh,&Separator);
  54.       FPuts(outfh,att->WABL_A_Value);
  55.       FPutC(outfh,10);
  56.       att=nat;
  57.      }
  58.    }
  59.    {
  60.     struct WABLFriend *fri,*nfr;
  61.     fri=obj->WABL_O_Friends.mlh_Head;
  62.     while (nfr=fri->WABL_F_Node.mln_Succ)
  63.      {
  64.       for (i=0;i<indent;i++)
  65.        {
  66.         FPutC(outfh,32);
  67.        } 
  68.       FPutC(outfh,'+');
  69.       FPuts(outfh,&BlueD);
  70.       FPuts(outfh,fri->WABL_F_Comm);
  71.       FPuts(outfh,&Separator);
  72.       FPuts(outfh,fri->WABL_F_Name);
  73.       FPutC(outfh,10);
  74.       fri=nfr;
  75.      }
  76.    }
  77.    if (!(obj->WABL_O_Childs.mlh_Head==&obj->WABL_O_Childs.mlh_Tail)) ShowTree(obj->WABL_O_Childs.mlh_Head); 
  78.    obj=nob;
  79.   }
  80.  indent--;
  81. }
  82.  
  83. ULONG ReadHook( register struct Hook* hook __asm("a0"), register ULONG object __asm("a2"), register ULONG message __asm("a1"))
  84. {
  85.  return(FGetC(object));
  86. }
  87.  
  88. int main()
  89. {
  90.  ULONG *rda,arg[1];
  91.  if (rda=ReadArgs("WABL/A",&arg,0))
  92.   {
  93.    ULONG *fh;
  94.    if (fh=Open(arg[ARG_WABLINPUT],MODE_OLDFILE))
  95.     {
  96.      struct WABL *wabl;
  97.      struct Hook gethook;
  98.      struct TagItem loadtags[3]={{WABL_FileHandle,fh},{WABL_GetCharHook,&gethook},{0,0}};
  99.      gethook.h_Entry=&ReadHook;
  100.      if (wabl=LoadWABL((struct TagItem*)loadtags))
  101.       {
  102.        outfh=Output();
  103.        ShowTree(wabl->WABL_Childs.mlh_Head);
  104.        FreeWABL(wabl);
  105.       }
  106.      Close(fh); 
  107.     }
  108.   }
  109. }
  110.  
  111.